﻿namespace NiYo.ParserBuilder.Domain.Hl7.DataTypes
{
    /// <summary>
    /// Entity identifier
    /// </summary>
    public class EntityIdentifier : Hl7DataType
    {
        /// <summary>
        /// The entity identifier
        /// Standard HL7 position: 1
        /// </summary>
        public string Identifier { get; set; }

        /// <summary>
        /// Used as the hl7 identifier for the user-defined table of values for this component.
        /// Standard HL7 position: 2
        /// </summary>
        public string NameSpaceId { get; set; }

        /// <summary>
        /// Universal Id.
        /// Standard HL7 position: 3
        /// </summary>
        public string UniversalId { get; set; }

        /// <summary>
        /// Universal Id Type.
        /// Standard HL7 position: 4
        /// </summary>
        public string UniversalIdType { get; set; }

        #region - Helper Methods -

        /// <summary>
        /// To compare current EntityIdentifier with another EntityIdentifier
        /// </summary>
        /// <returns></returns>
        private bool Equals(EntityIdentifier other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Equals(other) && Equals(other.Identifier, Identifier);
        }

        /// <summary>
        /// To compare current EntityIdentifier with another object
        /// </summary>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            return Equals(obj as EntityIdentifier);
        }

        /// <summary>
        /// Used by Equals method to compare objects
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            unchecked
            {
                {
                    var result = (Identifier != null ? Identifier.GetHashCode() : 0);
                    result = (result * 397) ^ (NameSpaceId != null ? NameSpaceId.GetHashCode() : 0);
                    result = (result * 397) ^ (UniversalId != null ? UniversalId.GetHashCode() : 0);
                    result = (result * 397) ^ (UniversalIdType != null ? UniversalIdType.GetHashCode() : 0);
                    return result;
                }
            }
        }

        #endregion
    }
}
